package vues;

import images.ImageResize;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

import vues.album.Album;
import vues.artiste.Artiste;

import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import java.awt.Toolkit;

public class MenuApp extends JFrame {
	private static final long serialVersionUID = 1L;

	private JPanel contentPane;
	private JButton btn_album;
	private JButton btn_artist;
	private JButton btn_apropos;
	private JLabel lbl_picture;
	private JButton btn_Quitter;
	private Artiste artiste = null;
	private Album album = null;

	/**
	 * Create the frame.
	 */
	public MenuApp() {
		setFont(new Font("Andalus", Font.PLAIN, 12));
		setIconImage(Toolkit.getDefaultToolkit().getImage(MenuApp.class.getResource("/images/connexion/utilisateur.png")));
		setTitle("TP2 - St\u00E9phanie et Rapha\u00EBl");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 665, 412);
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getBtn_album());
		contentPane.add(getBtn_artist());
		contentPane.add(getBtn_apropos());
		contentPane.add(getLbl_picture());
		contentPane.add(getBtn_Quitter());
		getRootPane().setDefaultButton(btn_Quitter);
		artiste = new Artiste();
		album = new Album();
	}

	private JButton getBtn_album() {
		if (btn_album == null) {
			btn_album = new JButton("");
			btn_album.setCursor(new Cursor(Cursor.HAND_CURSOR));
			btn_album.setVerticalAlignment(SwingConstants.BOTTOM);
			btn_album.setBounds(235, 31, 116, 107);
			btn_album.setIcon(new ImageIcon(MenuApp.class.getResource("/images/Album.png")));
			btn_album.setRolloverIcon(new ImageIcon(MenuApp.class.getResource("/images/AlbumAnimation.gif")));

			btn_album.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					album.update();
					album.setVisible(true);
				}
			});
		}
		return btn_album;
	}

	private JButton getBtn_artist() {
		if (btn_artist == null) {
			btn_artist = new JButton("");
			btn_artist.setCursor(new Cursor(Cursor.HAND_CURSOR));
			btn_artist.setIcon(new ImageIcon(MenuApp.class.getResource("/images/Artiste.png")));
			btn_artist.setRolloverIcon(new ImageIcon(MenuApp.class.getResource("/images/ArtisteAnimation.gif")));
			btn_artist.setBounds(52, 31, 116, 106);
			
			btn_artist.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					artiste.update();
					artiste.setVisible(true);
				}
			});
		}
		return btn_artist;
	}

	private JButton getBtn_apropos() {
		if (btn_apropos == null) {
			btn_apropos = new JButton("");
			btn_apropos.setCursor(new Cursor(Cursor.HAND_CURSOR));
			btn_apropos.setIcon(new ImageIcon(MenuApp.class.getResource("/images/Apropos.png")));
			btn_apropos.setRolloverIcon(new ImageIcon(MenuApp.class.getResource("/images/AproposAnimation.gif")));
			btn_apropos.setBounds(416, 31, 111, 107);
			btn_apropos.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					APropos apropos = new APropos();
					apropos.setVisible(true);
				}
			});
		}
		return btn_apropos;
	}

	private JLabel getLbl_picture() {
		if (lbl_picture == null) {
			lbl_picture = new JLabel("");
			lbl_picture.setHorizontalAlignment(SwingConstants.CENTER);
			lbl_picture.setLabelFor(this);
			lbl_picture.setBounds(163, 161, 284, 168);
			lbl_picture.setIcon(ImageResize.createImage(new ImageIcon(MenuApp.class.getResource("/images/disco_ball.gif")), lbl_picture.getWidth(), lbl_picture.getHeight()));
		}
		return lbl_picture;
	}

	private JButton getBtn_Quitter() {
		if (btn_Quitter == null) {
			btn_Quitter = new JButton("Quitter");
			btn_Quitter.setCursor(new Cursor(Cursor.HAND_CURSOR));
			btn_Quitter.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
				}
			});
			btn_Quitter.setFont(new Font("Andalus", Font.PLAIN, 18));
			btn_Quitter.setBounds(550, 340, 89, 23);
		}
		return btn_Quitter;

	}
}
